package org.com.yz.dubbo.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HttpContext;
import org.com.yz.common.util.AES;
import org.com.yz.common.util.CacheUtil;
import org.com.yz.common.util.ToolUtil;
import org.com.yz.common.util.XmlFormatter;
import org.com.yz.dal.dao.model.MchConfig;
import org.com.yz.dal.dao.model.WithdrawPay;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

/**
 * 提现工具类
 */
public class WithdrawPayUtil {
    private static Logger log = LoggerFactory.getLogger(WithdrawPayUtil.class);

    private static String ACCTID = "117010100100000177"; //付款账号
    private static String CID = "1100343164"; //商户号
    private static String USERID = "chenlong";
    private static String USERPASS = "a11111";
//    private static String payUrl = "http://47.98.144.54:8007"; //请求url

    private static String payUrl = "http://127.0.0.1:8007"; //请求url


    /**
     * 银企直联--提现
     *
     * @param mchNo
     * @param trunId
     * @param isSameBank
     * @param isSameCity
     * @param cardNo
     * @param accountName
     * @param bankName
     * @param bankNum
     * @param city
     * @param withdrawCash
     * @param isSuper
     * @param accntType
     * @return
     * @throws Exception
     */
    public static WithdrawPay withdrawPay(String mchNo, String trunId, String isSameBank, String isSameCity, String cardNo,
                                          String accountName, String bankName, String bankNum, String city,
                                          String withdrawCash, String isSuper, String accntType, String useRemark) throws Exception {
        MchConfig config = CacheUtil.me().getMchConfigInfo(mchNo, accntType);
        HttpClient client = HttpClientBuilder.create().build(); //创建请求客户端
        HttpPost request = new HttpPost(config.getPay_url()); //拼装请求xml并组装请求
        Document document = buildTradeRequestXml(mchNo, trunId, isSameBank, isSameCity, cardNo, accountName,
                bankName, bankNum, city, withdrawCash, isSuper, accntType, useRemark); //转账请求报文
        document.setXMLEncoding("gbk");
        String requestXml = document.asXML();
        ByteArrayEntity requestEntity = null;
        log.info(useRemark+"-请求报文如下：{}", XmlFormatter.formatXml(requestXml));
        try {
            requestEntity = new ByteArrayEntity(requestXml.getBytes("gbk"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            log.error(useRemark+"--xml写入请求编码错误");
        }
        log.info(useRemark+"--转账xml报文长度（字节）:{}", requestEntity.getContentLength());
        request.setEntity(requestEntity);
        request.setHeader("Content-Type", "application/x-fox");
        request.setHeader("Intensoft-Request-Sign", "YES");
        //发送请求并提取响应
        HttpResponse response = null;


        //setConnectTimeout：设置连接超时时间，单位毫秒。
        //
        //setConnectionRequestTimeout：设置从connect Manager(连接池)获取Connection 超时时间，单位毫秒。这个属性是新加的属性，因为目前版本是可以共享连接池的。
        //
        //setSocketTimeout：请求获取数据的超时时间(即响应时间)，单位毫秒。 如果访问一个接口，多少时间内无法返回数据，就直接放弃此次调用。
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(10000).setConnectionRequestTimeout(2000)
                .setSocketTimeout(10000).build();

        request.setConfig(requestConfig);

        response = client.execute(request);
        System.out.println("响应报文结果：" + response.getStatusLine().getStatusCode());

        //创建xml读取器并获取xml文件
        InputStreamReader reader = new InputStreamReader(response.getEntity().getContent(), "gbk");
        BufferedReader bufferedReader = new BufferedReader(reader);

        String results = "";
        int tmp;
        while ((tmp = bufferedReader.read()) != -1) {
            results += (char) tmp;
        }
        log.info(useRemark+"--返回数据：{}", results);

        WithdrawPay withdrawPay = requestXmlToObject(results);
        withdrawPay.setCreateTime(new DateTime());
        return withdrawPay;
    }


    /**
     * 转账请求xml拼装
     *
     * @param mchNo
     * @param trunId
     * @param isSameBank
     * @param isSameCity
     * @param cardNo
     * @param accountName
     * @param bankName
     * @param bankNum
     * @param city
     * @param withdrawCash
     * @param isSuper
     * @param accntType
     * @return
     */
    private static Document buildTradeRequestXml(String mchNo, String trunId, String isSameBank, String isSameCity,
                                                 String cardNo, String accountName, String bankName,
                                                 String bankNum, String city, String withdrawCash, String isSuper, String accntType, String useRemark) {
        MchConfig config = CacheUtil.me().getMchConfigInfo(mchNo, accntType);
        Document document = DocumentHelper.createDocument();
        Element ele = DocumentHelper.createElement("FOX");
        Element ele1 = DocumentHelper.createElement("SIGNONMSGSRQV1");
        Element ele3 = DocumentHelper.createElement("SONRQ");
        ele3.addElement("DTCLIENT").setText(DateUtil.now());
        ele3.addElement("CID").setText(config.getCid());
        ele3.addElement("USERID").setText(config.getUserid());
        ele3.addElement("USERPASS").setText(AES.getInstance().decrypt(config.getUserpass()));
        ele3.addElement("GENUSERKEY").setText("N");

        ele1.add(ele3);

        Element ele2 = DocumentHelper.createElement("SECURITIES_MSGSRQV1");
        Element ele4 = DocumentHelper.createElement("XFERTRNRQ");
        ele4.addElement("TRNUID").setText(trunId); //客户端交易的唯一标识 最大30位

        Element ele5 = DocumentHelper.createElement("XFERRQ");
        Element ele6 = DocumentHelper.createElement("XFERINFO");

        Element ele7 = DocumentHelper.createElement("ACCTFROM");
        ele7.addElement("ACCTID").setText(config.getAcctid()); //付款账号

        Element ele8 = DocumentHelper.createElement("ACCTTO");
        ele8.setAttributeValue("INTERBANK", isSameBank); //是否行内转账
        ele8.setAttributeValue("LOCAL", isSameCity); //是否同城转账

        ele8.addElement("ACCTID").setText(cardNo); //收款账号
        ele8.addElement("NAME").setText(accountName); //户名
        ele8.addElement("BANKDESC").setText(bankName); //银行名称

        ele8.addElement("BANKNUM").setText(bankNum); //行号
//        ele8.addElement("CITY").setText(city); //非同城要填写

        ele6.add(ele7);
        ele6.add(ele8);

        ele6.addElement("TRNAMT").setText(String.valueOf(withdrawCash));
        if ("1".equals(isSuper)) {
            ele6.addElement("PMTMODE").setText("SUPER"); //支付方式，超级网银支付必须填入“SUPER”
        }
        ele6.addElement("PURPOSE").setText(trunId);
        ele6.addElement("MEMO").setText("存管通提现");

        ele5.add(ele6);

        ele4.add(ele5);

        ele2.add(ele4);

        ele.add(ele1);
        ele.add(ele2);

        document.add(ele);
        return document;
    }


    /**
     * 解析转账请求返回结果
     *
     * @param responseXml
     * @return
     * @throws Exception
     */
    public static WithdrawPay requestXmlToObject(String responseXml) throws Exception {
        WithdrawPay withdrawPay = new WithdrawPay();

        Document document = DocumentHelper.parseText(responseXml);
        Element root = document.getRootElement();

        Element ele = root.element("SIGNONMSGSRSV1");
        Element ele1 = ele.element("SONRS");
        Element ele2 = ele1.element("STATUS");
        Element ele3 = ele2.element("CODE");
        Element ele4 = ele2.element("SEVERITY");
        if("ERROR".equals(ele4.getText())){
            Element messageEle = ele2.element("MESSAGE");
            withdrawPay.setMessage(messageEle.getText());
            withdrawPay.setXferprccode("FAIL"); //失败
            return withdrawPay;
        }

        Element ele5 = ele1.element("DTSERVER");

        Element ele6 = root.element("SECURITIES_MSGSRSV1");
        Element ele7 = ele6.element("XFERTRNRS");
//        Element ele7 = ele6.element("XFERINQTRNRS");

        Element ele8 = ele7.element("TRNUID");
        withdrawPay.setTrunId(ele8.getText()); //交易唯一标识ID

        Element ele9 = ele7.element("STATUS");
        Element ele10 = ele9.element("CODE");
        Element ele11 = ele9.element("SEVERITY");
        if(!"0".equals(ele10.getText())){ //0:正确
            Element messageEle = ele9.element("MESSAGE");
            withdrawPay.setMessage(messageEle.getText());
            withdrawPay.setXferprccode("FAIL"); //失败
            return withdrawPay;
        }

        Element ele12 = ele7.element("XFERRS");
        Element ele13 = ele12.element("SRVRID");

        Element ele14 = ele12.element("XFERINFO");
        Element ele15 = ele14.element("ACCTFROM");
        Element ele16 = ele15.element("ACCTID");
        withdrawPay.setAcctfromAcctid(ele16.getText());

        Element ele17 = ele15.element("NAME");
        withdrawPay.setAcctfromName(ele17.getText());

        Element ele18 = ele15.element("BANKDESC");
        withdrawPay.setAcctfromBankdesc(ele18.getText());

        Element ele19 = ele15.element("CITY");
        if (ToolUtil.isNotEmpty(ele19)) {
            withdrawPay.setAcctfromCity(ele19.getText());
        }


        Element ele20 = ele14.element("ACCTTO");
        String isSameBank = ele20.attributeValue("INTERBANK");
        withdrawPay.setAccttoInterbank(isSameBank);

        String isSameCity = ele20.attributeValue("LOCAL");
        withdrawPay.setAccttoLocal(isSameCity);

        Element ele21 = ele20.element("ACCTID");
        withdrawPay.setAccttoAcctid(ele21.getText());

        Element ele22 = ele20.element("NAME");
        withdrawPay.setAccttoName(ele22.getText());

        Element ele23 = ele20.element("BANKDESC");
        withdrawPay.setAccttoBankdesc(ele23.getText());

//            Element ele24 = ele20.element("BANKNUM");
//        withdrawPay.setAccttoBanknum(ele24.getText());

//        Element ele25 = ele20.element("CITY");
//        withdrawPay.setAccttoCity(ele25.getText());

//        Element ele26 = ele14.element("CHEQUENUM");

//        Element ele27 = ele14.element("CURSYM");
        Element ele28 = ele14.element("TRNAMT");
        withdrawPay.setTrnamt(ele28.getText());

//        Element ele29 = ele14.element("PMTMODE");
//        withdrawPay.setPmtmode(ele29.getText());

        Element ele30 = ele14.element("PURPOSE");
        withdrawPay.setPurpose(ele30.getText());

//        Element ele31 = ele14.element("DTDUE");
//        withdrawPay.setDtdue(ele31.getText());

        Element ele32 = ele14.element("MEMO");
        withdrawPay.setMemo(ele32.getText());

        Element ele33 = ele12.element("XFERPRCSTS");
        Element ele34 = ele33.element("XFERPRCCODE");
        withdrawPay.setXferprccode(ele34.getText());

        Element ele35 = ele33.element("DTXFERPRC");
        withdrawPay.setDtxferprc(ele35.getText());

        Element ele36 = ele33.element("MESSAGE");
        withdrawPay.setMessage(ele36.getText());

//        Element ele37 = ele12.element("CLIENTREF");
//        withdrawPay.setClientref(ele37.getText());

        return withdrawPay;
    }

    /**
     * 超级网银 转账查询
     *
     * @param mchNo
     * @param trunId
     * @param accntType
     * @return
     * @throws Exception
     */
    public static WithdrawPay withdrawPayQuery(String mchNo, String trunId, String accntType) throws Exception {
        MchConfig config = CacheUtil.me().getMchConfigInfo(mchNo, accntType);
        WithdrawPay withdrawPay = null;
        int reTryNum = 0;
        HttpClient client = HttpClientBuilder.create().build(); //创建请求客户端
        HttpPost request = new HttpPost(config.getPay_url()); //拼装请求xml并组装请求
        Document document = buildTradeStatusRequestXml(trunId, config); //转账查询请求报文
        document.setXMLEncoding("gbk");
        String requestXml = document.asXML();
        ByteArrayEntity requestEntity = null;
        log.info("超级网银转账查询-请求报文如下：{}", XmlFormatter.formatXml(requestXml));
        try {
            requestEntity = new ByteArrayEntity(requestXml.getBytes("gbk"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            log.error("超级网银转账查询-xml写入请求编码错误");
        }
        log.info("超级网银转账查询-转账xml报文长度（字节）:{}", requestEntity.getContentLength());
        request.setEntity(requestEntity);
        request.setHeader("Content-Type", "application/x-fox");
        request.setHeader("Intensoft-Request-Sign", "YES");
        //发送请求并提取响应
        HttpResponse response = null;
        try {
            response = client.execute(request);
            System.out.println("超级网银转账查询-响应报文结果：" + response.getStatusLine().getStatusCode());

            //创建xml读取器并获取xml文件
            InputStreamReader reader = new InputStreamReader(response.getEntity().getContent(), "gbk");
            BufferedReader bufferedReader = new BufferedReader(reader);

            String results = "";
            int tmp;
            while ((tmp = bufferedReader.read()) != -1) {
                results += (char) tmp;
            }
            log.info("超级网银转账查询-返回数据：{}", results);
            /*results = "<FOX>\n" +
                    "    <SIGNONMSGSRSV1>\n" +
                    "        <SONRS>\n" +
                    "            <STATUS>\n" +
                    "                <CODE>0</CODE>\n" +
                    "                <SEVERITY>INFO</SEVERITY>\n" +
                    "            </STATUS>\n" +
                    "            <DTSERVER>2014-11-19 14:31:31</DTSERVER>\n" +
                    "        </SONRS>\n" +
                    "    </SIGNONMSGSRSV1>\n" +
                    "    <SECURITIES_MSGSRSV1>\n" +
                    "        <XFERINQTRNRS>\n" +
                    "            <TRNUID>25293192132xxxxxxxx</TRNUID>\n" +
                    "            <STATUS>\n" +
                    "                <CODE>0</CODE>\n" +
                    "                <SEVERITY>INFO</SEVERITY>\n" +
                    "            </STATUS>\n" +
                    "            <XFERINQRS>\n" +
                    "                <XFERLIST MORE=\"N\">\n" +
                    "                    <FROM>006014126744</FROM>\n" +
                    "                    <TO>006014126744</TO>\n" +
                    "                    <XFER>\n" +
                    "                        <SRVRTID>006014126744</SRVRTID>\n" +
                    "                        <XFERINFO>\n" +
                    "                            <ACCTFROM>\n" +
                    "                                <ACCTID>117010100150190084</ACCTID>\n" +
                    "                                <NAME>银企测试182</NAME>\n" +
                    "                                <CITY>福州</CITY>\n" +
                    "                            </ACCTFROM>\n" +
                    "                            <ACCTTO INTERBANK=\"Y\" LOCAL=\"Y\">\n" +
                    "                                <ACCTID>117010100100076908</ACCTID>\n" +
                    "                                <NAME>test1</NAME>\n" +
                    "                                <BANKDESC>兴业银行总行营业部</BANKDESC>\n" +
                    "                                <CITY>fz</CITY>\n" +
                    "                            </ACCTTO>\n" +
                    "                            <CHEQUENUM>01343120</CHEQUENUM>\n" +
                    "                            <CURSYM>RMB</CURSYM>\n" +
                    "                            <TRNAMT>1.24</TRNAMT>\n" +
                    "                            <PMTMODE>SUPER</PMTMODE>\n" +
                    "                            <PURPOSE>转账给冥冥吃饭</PURPOSE>\n" +
                    "                            <MEMO>备注1119</MEMO>\n" +
                    "                        </XFERINFO>\n" +
                    "                        <XFERPRCSTS>\n" +
                    "                            <XFERPRCCODE>PAYOUT</XFERPRCCODE>\n" +
                    "                            <DTXFERPRC>2014-11-19 14:23:11</DTXFERPRC>\n" +
                    "                            <MESSAGE>交易成功</MESSAGE>\n" +
                    "                        </XFERPRCSTS>\n" +
                    "                    </XFER>\n" +
                    "                </XFERLIST>\n" +
                    "            </XFERINQRS>\n" +
                    "        </XFERINQTRNRS>\n" +
                    "      </SECURITIES_MSGSRSV1> \n" +
                    "</FOX>";*/
            withdrawPay = queryXmlToObject(results);
            return withdrawPay;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("超级网银转账查询-异常：{}", e.toString());

            //如果请求代理软件出现异常，每个10秒钟再次请求一次
            Thread.sleep(1000*10);
            reTryNum ++;
            log.error("超级网银转账查询-异常重试：{}", reTryNum);
            withdrawPay = withdrawPayQuery(mchNo, trunId, accntType);
        }
        return withdrawPay;
    }

    //转账交易请求xml
    private static Document buildTradeRequestXml(String trunId, String isSameBank, String isSameCity,
                                                 String cardNo, String accountName, String bankName,
                                                 String bankNum, String city, String withdrawCash) {
        Document document = DocumentHelper.createDocument();
        Element ele = DocumentHelper.createElement("FOX");
        Element ele1 = DocumentHelper.createElement("SIGNONMSGSRQV1");
        Element ele3 = DocumentHelper.createElement("SONRQ");
        ele3.addElement("DTCLIENT").setText(org.com.yz.common.util.DateUtil.getCurrentDate());
        ele3.addElement("CID").setText(CID);
        ele3.addElement("USERID").setText(USERID);
        ele3.addElement("USERPASS").setText(USERPASS);
        ele3.addElement("GENUSERKEY").setText("N");

        ele1.add(ele3);

        Element ele2 = DocumentHelper.createElement("SECURITIES_MSGSRQV1");
        Element ele4 = DocumentHelper.createElement("XFERTRNRQ");
        ele4.addElement("TRNUID").setText(trunId); //客户端交易的唯一标识 最大30位

        Element ele5 = DocumentHelper.createElement("XFERRQ");
        Element ele6 = DocumentHelper.createElement("XFERINFO");

        Element ele7 = DocumentHelper.createElement("ACCTFROM");
        ele7.addElement("ACCTID").setText(ACCTID); //付款账号

        Element ele8 = DocumentHelper.createElement("ACCTTO");
        ele8.setAttributeValue("INTERBANK", isSameBank); //是否行内转账
        ele8.setAttributeValue("LOCAL", isSameCity); //是否同城转账

        ele8.addElement("ACCTID").setText(cardNo); //收款账号
        ele8.addElement("NAME").setText(accountName); //户名
        ele8.addElement("BANKDESC").setText(bankName); //银行名称

        ele8.addElement("BANKNUM").setText(bankNum); //行号
//        ele8.addElement("CITY").setText(city); //非同城要填写

        ele6.add(ele7);
        ele6.add(ele8);

        ele6.addElement("TRNAMT").setText(withdrawCash);
        ele6.addElement("PMTMODE").setText("SUPER"); //支付方式，超级网银支付必须填入“SUPER”
        ele6.addElement("PURPOSE").setText("摇钱吧提现");
        ele6.addElement("MEMO").setText("摇钱吧提现");

        ele5.add(ele6);

        ele4.add(ele5);

        ele2.add(ele4);

        ele.add(ele1);
        ele.add(ele2);

        document.add(ele);
        return document;
    }

    /**
     * 转账查询请求报文拼接
     *
     * @param trunId
     * @param config
     * @return
     */
    private static Document buildTradeStatusRequestXml(String trunId, MchConfig config) {
        Document document = DocumentHelper.createDocument();

        Element ele = DocumentHelper.createElement("FOX");
        Element ele1 = DocumentHelper.createElement("SIGNONMSGSRQV1");
        Element ele2 = DocumentHelper.createElement("SONRQ");
        ele2.addElement("DTCLIENT").setText(org.com.yz.common.util.DateUtil.getCurrentDate());
        ele2.addElement("CID").setText(config.getCid());
        ele2.addElement("USERID").setText(config.getUserid());
        ele2.addElement("USERPASS").setText(AES.getInstance().decrypt(config.getUserpass()));
        ele2.addElement("GENUSERKEY").setText("N");
        ele2.addElement("APPID").setText("XYFIB");
        ele2.addElement("APPVER").setText("1000");

        ele1.add(ele2);

        Element ele3 = DocumentHelper.createElement("SECURITIES_MSGSRQV1");
        Element ele4 = DocumentHelper.createElement("XFERINQTRNRQ");
        ele4.addElement("TRNUID").setText(trunId);

        Element ele5 = DocumentHelper.createElement("XFERINQRQ");
        ele5.addElement("CLIENTREF").setText(trunId);

        ele4.add(ele5);

        ele3.add(ele4);

        ele.add(ele1);
        ele.add(ele3);

        document.add(ele);

        return document;
    }


    /**
     * 转账查询 --返回报文解析
     *
     * @param responseXml
     * @return
     * @throws Exception
     */
    public static WithdrawPay queryXmlToObject(String responseXml) throws Exception {
        WithdrawPay withdrawPay = new WithdrawPay();

        Document document = DocumentHelper.parseText(responseXml);
        Element root = document.getRootElement();

        Element ele = root.element("SIGNONMSGSRSV1");
        Element ele1 = ele.element("SONRS");
        Element ele2 = ele1.element("STATUS");
        Element ele3 = ele2.element("CODE");
        Element ele4 = ele2.element("SEVERITY");

        Element ele5 = ele1.element("DTSERVER");

        Element ele6 = root.element("SECURITIES_MSGSRSV1");
//        Element ele7 = ele6.element("XFERTRNRS");
        Element ele7 = ele6.element("XFERINQTRNRS");

        Element ele8 = ele7.element("TRNUID");
        withdrawPay.setTrunId(ele8.getText()); //交易唯一标识ID

        Element ele9 = ele7.element("STATUS");
        Element ele10 = ele9.element("CODE");
        Element ele11 = ele9.element("SEVERITY");

        Element ele12 = ele7.element("XFERINQRS");
        Element ele13 = ele12.element("SRVRID");

        Element xferlist = ele12.element("XFERLIST");
        Element xfer = xferlist.element("XFER");

        Element ele14 = xfer.element("XFERINFO");
        Element ele15 = ele14.element("ACCTFROM");
        Element ele16 = ele15.element("ACCTID");
        withdrawPay.setAcctfromAcctid(ele16.getText());

        Element ele17 = ele15.element("NAME");
        withdrawPay.setAcctfromName(ele17.getText());

//        Element ele18 = ele15.element("BANKDESC");
//        withdrawPay.setAcctfromBankdesc(ele18.getText());

        Element ele19 = ele15.element("CITY");
        if (ToolUtil.isNotEmpty(ele19)) {
            withdrawPay.setAcctfromCity(ele19.getText());
        }


        Element ele20 = ele14.element("ACCTTO");
        String isSameBank = ele20.attributeValue("INTERBANK");
        withdrawPay.setAccttoInterbank(isSameBank);

        String isSameCity = ele20.attributeValue("LOCAL");
        withdrawPay.setAccttoLocal(isSameCity);

        Element ele21 = ele20.element("ACCTID");
        withdrawPay.setAccttoAcctid(ele21.getText());

        Element ele22 = ele20.element("NAME");
        withdrawPay.setAccttoName(ele22.getText());

        Element ele23 = ele20.element("BANKDESC");
        withdrawPay.setAccttoBankdesc(ele23.getText());

//        Element ele24 = ele20.element("BANKNUM");
//        withdrawPay.setAccttoBanknum(ele24.getText());

//        Element ele25 = ele20.element("CITY");
//        withdrawPay.setAccttoCity(ele25.getText());

        Element ele26 = ele14.element("CHEQUENUM");

        Element ele27 = ele14.element("CURSYM");
        Element ele28 = ele14.element("TRNAMT");
        withdrawPay.setTrnamt(ele28.getText());

        Element ele29 = ele14.element("PMTMODE");
        withdrawPay.setPmtmode(ele29.getText());

        Element ele30 = ele14.element("PURPOSE");
        withdrawPay.setPurpose(ele30.getText());

//        Element ele31 = ele14.element("DTDUE");
//        withdrawPay.setDtdue(ele31.getText());

        Element ele32 = ele14.element("MEMO");
        withdrawPay.setMemo(ele32.getText());

        Element ele33 = xfer.element("XFERPRCSTS");
        Element ele34 = ele33.element("XFERPRCCODE");
        withdrawPay.setXferprccode(ele34.getText());

        Element ele35 = ele33.element("DTXFERPRC");
        withdrawPay.setDtxferprc(ele35.getText());

        Element ele36 = ele33.element("MESSAGE");
        withdrawPay.setMessage(ele36.getText());

//        Element ele37 = ele12.element("CLIENTREF");
//        withdrawPay.setClientref(ele37.getText());

        return withdrawPay;
    }

}
